package com.ext.demoredis.controller;

import com.ext.demoredis.common.DistributedLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class testController {

    @Autowired
    private DistributedLock distributedLock;

    @RequestMapping("/get1")
    public String getLock(){
        String value = "good";
        String LOCK_ID ="lock";
        boolean lock = distributedLock.getLock(LOCK_ID, value,10 * 1000);
        if (lock) {
            System.out.println("执行任务");
            distributedLock.releaseLock(LOCK_ID);
        } else {
            System.out.println("没有抢到锁");
        }
        return "good";
    }
}
